//
//  HourseCategoryCountCell.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/8.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HourseCategoryCountCell.h"
#import "UIImageView+WebCache.h"
#import "config.h"
#import "Tools.h"
#import "UIButton+WebCache.h"



@interface HourseCategoryCountCell ()
@property (weak, nonatomic) IBOutlet UILabel *countLab;




@property (weak, nonatomic) IBOutlet UILabel *leftTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *rightTitleLab;


@property (weak, nonatomic) IBOutlet UILabel *leftAreaLab;

@property (weak, nonatomic) IBOutlet UILabel *rightAreaLab;
@property (weak, nonatomic) IBOutlet UILabel *leftGejuLab;

@property (weak, nonatomic) IBOutlet UILabel *rightGejuLab;

@end


@implementation HourseCategoryCountCell




+(instancetype) cellWithTableView:(UITableView *)tableview;
{
    static NSString *ID = @"HourseCategoryCountCell";
    HourseCategoryCountCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"HourseCategoryCountCell" owner:nil options:nil]lastObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        

        cell.leftBtn.layer.borderColor = UIColorFromRGB(0xe3e3e3).CGColor;
        cell.leftBtn.layer.borderWidth = 1;

        cell.rightBtn.layer.borderColor = UIColorFromRGB(0xe3e3e3).CGColor;
        cell.rightBtn.layer.borderWidth = 1;
    }
    
    return cell;
}


+(CGFloat)getHight:(HourseCagegoryCellData *)data withTableView:(UITableView *)tableView{
    
    static HourseCategoryCountCell *cell = nil;
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        
        cell = [HourseCategoryCountCell cellWithTableView:tableView];
    });
    
    [cell setData:data];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
    return  height+1;
}


-(void)setData:(HourseCagegoryCellData*)data{
    
    
    [self.leftBtn setBackgroundColor:NoImgColor];
    [self.rightBtn setBackgroundColor:NoImgColor];
    
    
    [self.countLab setPreferredMaxLayoutWidth:self.countLab.frame.size.width];
    [self.leftTitleLab setPreferredMaxLayoutWidth:self.leftTitleLab.frame.size.width];
    [self.leftAreaLab setPreferredMaxLayoutWidth:self.leftAreaLab.frame.size.width];
    [self.leftGejuLab setPreferredMaxLayoutWidth:self.leftGejuLab.frame.size.width];
    
    [self.rightTitleLab setPreferredMaxLayoutWidth:self.rightTitleLab.frame.size.width];
    [self.rightAreaLab setPreferredMaxLayoutWidth:self.rightAreaLab.frame.size.width];
    [self.rightGejuLab setPreferredMaxLayoutWidth:self.rightGejuLab.frame.size.width];
    
    
    [self.countLab setText:[NSString stringWithFormat:@"%d"
                            ,data.allCouont]];
    
    HourseCagegoryData *left = data.leftData;
    HourseCagegoryData *right = data.rightData;
    
    if (left) {
        
        [self.leftBtn sd_setImageWithURL:[NSURL URLWithString:left.imgUrl] forState:UIControlStateNormal placeholderImage:nil];
        self.leftBtn.tag = [left.dataId integerValue];
        [self.leftTitleLab setText:left.title];
        [self.leftAreaLab setText:left.area];
        [self.leftGejuLab setText:left.geJu];
    }

    if (right) {
        
        [self.rightBtn sd_setImageWithURL:[NSURL URLWithString:right.imgUrl] forState:UIControlStateNormal placeholderImage:nil];
         self.rightBtn.tag = [right.dataId integerValue];
        [self.rightTitleLab setText:right.title];
        [self.rightAreaLab setText:right.area];
        [self.rightGejuLab setText:right.geJu];
    }
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
